import org.kwis.msp.lcdui.*;
import org.kwis.msp.lwc.*;
import java.util.Random;

public class Ball implements GameConstants
{
	private Image img = null;
	private int x,y;
	private int deltaX, deltaY;
	Random rand = new Random();

	public Ball(int cx, int cy)
	{
		x = cx;
		y = cy;

		try
		{
			img = Image.createImage("ball.png");
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public void setPosX(int posx)
	{
		x = posx;
	}

	public void setPosY(int posy)
	{
		y = posy;
	}


	public int getX()
	{ 
		return x;
	}

	public int getY()
	{
		return y;
	}

	public int getDeltaX()
	{
		return deltaX;
	}

	public int getDeltaY()
	{
		return deltaY;
	}

	public void inverseDeltaX()
	{
		deltaX = -deltaX;
	}

	public void inverseDeltaY()
	{
		deltaY = -deltaY;
	}

	public void move()
	{
		x += deltaX;
		y += deltaY;
	}

	public void moveTo(int px, int py)
	{
		x = px;
		y = py;
	}

	public void initialize()
	{
		if ((rand.nextInt()%2 == 0))
		{
			deltaX = BALL_MOVE;
		}
		else
			deltaX = -BALL_MOVE;

		deltaY = -BALL_MOVE;
	}

	public void paint(Graphics g)
	{
		g.drawImage(img,x,y,Graphics.TOP);
	}
}